package com.shrw.duke.serialport.common.enity;

import java.io.Serializable;

/**
 * Created by rw-duke on 2018/1/11.
 */

public class RFArgEnity implements Serializable{
    private String head = "02030405";
    private String length ="001B";
    private String devId = "00000058";
    private String cmd = "10";
    private String sn = "01";
    private String encryption = "00";
    private String rfHead = "01";
    private String labelType;
    private String air;
    private String channel;
    private String distance = "64";
    private String rev = "0001020304050607";
    private String checkSum = "00";
//02030405  001B    C30AE002    11  0100    01  12001A64000102030405060797
    private StringBuilder stringBuilder;

    public RFArgEnity(){
    }

    public String getHead() {
        return head;
    }

    public void setHead(String head) {
        this.head = head;
    }

    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getDevId() {
        return devId;
    }

    public void setDevId(String devId) {
        this.devId = devId;
    }

    public String getCmd() {
        return cmd;
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getEncryption() {
        return encryption;
    }

    public void setEncryption(String encryption) {
        this.encryption = encryption;
    }

    public String getRfHead() {
        return rfHead;
    }

    public void setRfHead(String rfHead) {
        this.rfHead = rfHead;
    }

    public String getLabelType() {
        return labelType;
    }

    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }

    public String getAir() {
        return air;
    }

    public void setAir(String air) {
        this.air = air;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }

    public String getRev() {
        return rev;
    }

    public void setRev(String rev) {
        this.rev = rev;
    }

    public String getCheckSum() {
        return checkSum;
    }

    public void setCheckSum(String checkSum) {
        this.checkSum = checkSum;
    }

    public StringBuilder getStringBuilder() {
        return stringBuilder;
    }

    public void setStringBuilder(StringBuilder stringBuilder) {
        this.stringBuilder = stringBuilder;
    }

    //02030405001B71B8FD431001000113012564000102030405060700
    @Override
    public String toString() {
        stringBuilder = new StringBuilder();
        stringBuilder.append(head);
        stringBuilder.append(length);
        stringBuilder.append(devId);
        stringBuilder.append(cmd);
        stringBuilder.append(sn);
        stringBuilder.append(encryption);
        stringBuilder.append(rfHead);
        stringBuilder.append(labelType);
        stringBuilder.append(air);
        stringBuilder.append(channel);
        stringBuilder.append(distance);
        stringBuilder.append(rev);
        stringBuilder.append(checkSum);
        return stringBuilder.toString().toUpperCase();
    }

    /**
     * 解析射频参数
     * @param data
     */
    public void parse(String data) {
        try{
            if (data != "" &&data != null){
                stringBuilder = new StringBuilder(data);
                cmd = stringBuilder.substring(20,22);
                head = stringBuilder.substring(0,8);
                length = stringBuilder.substring(8,12);
                devId = stringBuilder.substring(12,20);
                sn = stringBuilder.substring(22,24);
                encryption = stringBuilder.substring(24,26);
                rfHead = stringBuilder.substring(26,28);
                labelType = stringBuilder.substring(28,30);
                air = stringBuilder.substring(30,32);
                channel = stringBuilder.substring(32,34);
                distance = stringBuilder.substring(34,36);
                rev = stringBuilder.substring(36,52);
//                checkSum = stringBuilder.substring(52,54);
                checkSum = "00";
            }

        }catch (StringIndexOutOfBoundsException e){
            e.toString();
        }
    }
}
